import Web3 from 'web3'
import Abi from './ContractAbi'
import address from './contractAddress'
// console.log(Abi.ERC20ABI, 'abi', address)
/* eslint-disable */
export const initWeb3 = function () {
  if (window.ethereum) {
    const web3 = new Web3(window.ethereum)
    // console.log(web3)
    return web3
  }
}

export const netWorkId = async function () {
  const web3 = initWeb3()
  const networkId = await web3.eth.net.getId()
  console.log('networkId:', networkId)
  return networkId
}

export function initContract () {
  const web3 = initWeb3()
  // console.log(web3, 'ppppp')
  // this.imeetContract = new web3.eth.Contract(Abi.yyNFTAbi, this.addressVal)
  const ImeetERC20Contract = new web3.eth.Contract(Abi.ImeetERC20ABI, address.ImeetERC20Address)
  const ImeetERC721Contract = new web3.eth.Contract(Abi.ImeetERC721ABI, address.ImeetERC721Address)
  const ImeetExchangeContract = new web3.eth.Contract(Abi.ImeetExchangeABI, address.ImeetExchangeAddress)
  // console.log(ERC20Contract, ERC721Contract)
  const ContractCollection = {
    ImeetERC20Contract: ImeetERC20Contract,
    ImeetERC721Contract: ImeetERC721Contract,
    ImeetExchangeContract: ImeetExchangeContract
  }
  return ContractCollection
}
